package com.flyme.common.core.utils;

import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;

public class ObjectUtils {
    public ObjectUtils() {
    }

    public static boolean isNull(Object... objs) {
        Object[] var1 = objs;
        int var2 = objs.length;

        for (int var3 = 0; var3 < var2; ++var3) {
            Object obj = var1[var3];
            if (isEmpty(obj)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isNotNull(Object... obj) {
        return !isNull(obj);
    }

    public static boolean isNotEmpty(Object obj) {
        return !isEmpty(obj);
    }

    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        } else if (obj.getClass().isArray()) {
            return Array.getLength(obj) == 0;
        } else if (obj instanceof CharSequence) {
            return ((CharSequence) obj).length() == 0;
        } else if ((obj instanceof String)) {
            return ((String) obj).trim().equals("");
        } else if (obj instanceof Collection) {
            return ((Collection) obj).isEmpty();
        } else {
            return obj instanceof Map ? ((Map) obj).isEmpty() : false;
        }
    }

    /**
     * 以UUID重命名
     *
     * @param fileName
     * @return
     */
    public static String renamePic(String fileName) {
        String extName = fileName.substring(fileName.lastIndexOf("."));
        return UUID.randomUUID().toString().replace("-", "") + extName;
    }

    /**
     * 返回字符串如为空返回默认值
     */
    public static String getParameter(String param) {
        String str = SpringContextHolder.getRequest().getParameter(param);
        if (ObjectUtils.isEmpty(str)) {
            return "";
        }
        return str;
    }

    /**
     * 返回字符串如为空返回默认值
     */
    public static String getParameter(String param, String defval) {
        String str = getParameter(param);
        if (ObjectUtils.isEmpty(str)) {
            return defval;
        }
        return str;
    }

    /**
     *
     */
    public static BigDecimal gertBigDecimal(BigDecimal v, String defval) {
        if (ObjectUtils.isEmpty(v)) {
            return new BigDecimal(defval);
        }
        return v;
    }

    /**
     *
     */
    public static Integer gertIngeter(Integer v, Integer defval) {
        if (ObjectUtils.isEmpty(v)) {
            return defval;
        }
        return v;
    }

    /**
     * 中文數字转阿拉伯数组【十万九千零六十  --> 109060】
     */
    @SuppressWarnings("unused")
    public static String chineseNumber2Int(String chineseNumber) {
        String[] s1 = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        String[] s2 = {"十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"};
        String result = "";
        int n = chineseNumber.length();
        for (int i = 0; i < n; i++) {
            int num = chineseNumber.charAt(i) - '0';
            if (i != n - 1 && num != 0) {
                result += s1[num] + s2[n - 2 - i];
            } else {
                result += s1[num];
            }
            System.out.println("  " + result);
        }
        return result;
    }
}
